<div class="search-res-mask"></div>
<div class="search-res">
    <div class="search-res-btn hide-pc">
        <button class="layui-btn" id="search-btn"><i class="layui-icon">&#xe615;</i>查询</button>
    </div>
    <div class="content-search search-fix">
        <div class="layui-form layui-form-pane">
            <div class="layui-inline">
                <label class="layui-form-label">登录时间</label>
                <div class="layui-input-inline" style="width:320px;">
                    <input type="text" class="layui-input" value="${timeRange}" id="timeRange" placeholder="请选择一个范围">
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn" id="btn_search" lay-submit="">查询</button>
                <button class="layui-btn layui-btn-primary hide-pc" id="search-close">关闭</button>
            </div>
        </div>
    </div>
</div>
<div class="tar mt10">
    <#if adminID != "">
        <a class="layui-btn layui-btn-small" href="/administrate/admin">返回</a>
    </#if>
</div>
<div class="table-list">
    <table class="layui-table layui-list-table">
        <thead>
        <tr>
            <th>管理员</th>
            <th>事件</th>
            <th>IP</th>
            <th>操作时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <#list data as d>
            <tr>
                <td class="layui-table-first"><i class="layui-table-hd">管理员</i><span
                        class="layui-table-bd">${d.adminName}</span></td>
                <td><i class="layui-table-hd">事件</i><span class="layui-table-bd">${d.eventsignature}</span></td>
                <td><i class="layui-table-hd">IP</i><span class="layui-table-bd">${d.ip}</span></td>
                <td><i class="layui-table-hd">操作时间</i><span class="layui-table-bd">${d.committime?string("yyyy-MM-dd HH:mm:ss")}</span>
                </td>
                <td>
                    <#if shiro.hasPermission("sys:commitlog:detail")>
                        <button class="layui-btn layui-btn-small btn_detail" data-id="${d.id}">详细
                        </button>
                    </#if>
                </td>
            </tr>
        </#list>
        </tbody>
    </table>
</div>
<!-- 分页 -->
<div id="pages" class="tac"></div>
<#macro script>
    <script id="detail" type="text/html">
        <table class="layui-table" lay-skin="nob">
            <tbody>
            <tr>
                <th>管理员</th>
                <td>{{ d.adminName }}</td>
            </tr>
            <tr>
                <th>事件</th>
                <td>{{ d.eventsignature }}</td>
            </tr>
            <tr>
                <th>方法</th>
                <td>{{ d.method }}</td>
            </tr>
            <tr>
                <th>参数</th>
                <td><textarea name="remark" disabled="disabled" class="layui-textarea">{{ d.params }}</textarea></td>
            </tr>
            <tr>
                <th>IP</th>
                <td>{{ d.ip }}</td>
            </tr>
            <tr>
                <th>操作时间</th>
                <td>{{ d.committime }}</td>
            </tr>
            </tbody>
        </table>
    </script>
    <script>
        layui.use(['jquery', 'laypage', 'laydate', 'laytpl'], function () {
            var $ = layui.jquery, laypage = layui.laypage
                , laydate = layui.laydate
                , laytpl = layui.laytpl;
            laydate.render({
                elem: '#timeRange'
                , type: 'datetime'
                , range: true
            });
            $(function () {
                /*弹出搜索*/
                $(document).on('click', '#search-btn', function () {
                    $('.search-res-mask').show();
                    $(this).parent().siblings('.search-fix').addClass('cur');
                });
                /*搜索*/
                $("#btn_search").on('click', function () {
                    reload(1);
                });
                /*关闭搜索*/
                $(document).on('click', '#search-close', function () {
                    $('.search-res-mask').hide();
                    $(this).parents('.search-fix').removeClass('cur');
                });
                /*查看详细*/
                $(".btn_detail").on("click", function () {
                    var id = $(this).data("id");
                    $.ajax({
                        type: "GET",
                        url: "/administrate/commitlog/detail/?id=" + id,
                        async: false,
                        dataType: "json",
                        success: function (result) {
                            if (result.code == 200) {
                                result.data.committime = new Date(result.data.committime).Format("yyyy-MM-dd hh:mm:ss");
                                var detailHtml = '';
                                laytpl(detail.innerHTML).render(result.data, function (html) {
                                    detailHtml = html;
                                });
                                var index = layer.open({
                                    title: '详细',
                                    content: detailHtml
                                });
                                layer.full(index);
                            }
                            else {
                                layer.msg(result.msg);
                            }
                        }
                    });
                });
            });
            laypage.render({
                elem: 'pages'
                , layout: ['prev', 'page', 'next', 'count']
                , count: ${dataCount}
                , limit: ${pageSize}
                , curr: ${pageNo}
                , groups: 2
                , jump: function (obj, first) {
                    if (!first) {
                        reload(obj.curr)
                    }
                }
            });

            function reload(currPage) {
                var timeRange = $("#timeRange").val();
                location.href = window.location.pathname + "?adminID=${adminID}&timeRange=" + timeRange + "&pageNo=" + currPage;
            }

        });
    </script>
</#macro>